<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
  String xm = this.getServletContext().getInitParameter("path");
	String path1 = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+"/"+xm;
%>  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>修改销售机会信息</title>
<link href="<%=path1%>/css/css.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=path1%>/scripts/jquery-1.7.2.js"></script>
<script type="text/javascript" src="<%=path1%>/scripts/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="<%=path1%>/scripts/pagekage/utils/widget/jqGrid/jquery.jqGrid.src.js"></script>
<script type="text/javascript" src="<%=path1%>/scripts/pagekage/utils/widget/jqGrid/i18n/grid.locale-cn.js"></script>
<script type="text/javascript" src="<%=path1%>/scripts/pagekage/utils/widget/jqGrid/jquery.jqGrid.min.js"></script>

<!--[if IE 6]>
<script type="text/javascript" src="js/ie6png.js" ></script>
<script type="text/javascript">
DD_belatedPNG.fix('div,ul,li,a,p,img,body,dl,dt,dd');</script>
<![endif]-->
<script type="text/javascript">
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
</script>
<!-- 项目、楼栋、单元、房间查询 -->
<script type="text/javascript">
var project_id,build_id,unit_id,room_id;	
$(document).ready(function(){
	//获得ID
	var SeachSql;
	var id;
    var str=window.location.href; //得到listclient的地址
    var es=/id=/; 
    es.exec(str); //得到地址后面变量名称
    //alert("es--"+es.exec(str));
    var right=RegExp.rightContext;//得到地址后面变量名称的值
    //alert("right-"+right);

    id=right;//将结果赋值给id
    $("#id").val(id);
    if(id!="" )
	  {
	     SearchSql ="  and s.sale_chance_id= '"+right+"'";
	  }
//    alert(SearchSql);
    $.ajax({
    	url:"Sale_Chance/selectBySql.do",
        datatype:'json', 
        data:{'page':1,'rows':1,'SearchSql':SearchSql}, // 发送数据   
        error:function(data){ 
        	
            alert("总出错了！！");  
       },  
       success:function(data){

       	var len=data.rows.length;
       	
       		//alert( data.rows[0].id);
           	//alert( data.rows[0].customer_name);
           //	alert( data.rows[0].tel);
            //alert( "project_id-----"+data.rows[0].project_id);
            //alert( "build_id-----"+data.rows[0].build_id);
            $("#user_id").val(data.rows[0].user_id);
           	$("#sale_chance_name").val(data.rows[0].sale_chance_name);
            $("#customer_name").val(data.rows[0].customer_name);
            
           // selectcustomer_name();
            //select();
        	$("#number").val(data.rows[0].number);
        	$("#userName").val(data.rows[0].user_name);
        	$("#intention_description").val(data.rows[0].intention_description);       	
        	$("#tel").val(data.rows[0].tel);    
        	
        	project_id=data.rows[0].project_id;
        	alert(project_id);
        	//$("#project").val(data.rows[0].project_id);
           	build_id=data.rows[0].build_id;
           	//selectUnit();
        	unit_id=data.rows[0].unit_id;
           	//selectRoom();
        	room_id=data.rows[0].room_id; 

        	//查询项目
        	$.ajax({
    	    	url:"./ht/project/selectAll1.do",
    	        datatype:'json', 
    	        //data:{'SeachSql':""}, // 发送数据   
    	        error:function(data){  
    	            alert("12333出错了！！");  
    	       },  
    	       success:function(data){
    	       	var len=data.rows.length;
    	  //     	alert("namber:"+data.rows.length);
    	        var select = document.getElementById("project");
    	        if(len>0){
    	           	for(var i=0;i<=len;i++){
    	           		select.options.add(new Option(data.rows[i].project_name, data.rows[i].project_id)); 
    	           		alert(select.options.length);
    	           		alert(project_id);
    	           		if(select.options[i].value==project_id){
		           			select.options[i].selected=true;
		          	       SearchSql=" and project_id='"+project_id+"'";
		          	       //查询楼栋
		          	       $.ajax({
		          		    	url:"ht/build/selectBySql.do",
		          		        datatype:'json', 
		          		        data:{'SearchSql':SearchSql}, // 发送数据   
		          		        error:function(data){  
		          		            alert("出错了！！");  
		          		       },  
		          		       success:function(data){
		          		       	var len=data.rows.length;
		          		       	//alert("namber----:"+data.rows.length);
		          		        var select1 = document.getElementById("build");
		          		       	if(len>0){
		          		           	for(var i=0;i<=len;i++){
		          		           		//alert("ccccccc"+build_id);
		          		           		//alert("12121");
		          		           	    select1.options.add(new Option(data.rows[i].build_name, data.rows[i].build_id)); 
		          		           		//alert("楼栋："+build_id);
		          		           	    if(select1.options[i].value==build_id){
		          		           	//		alert("build_id"+select1.options[i].value);
		          		           			select1.options[i].selected=true;
		          		           			//查询单元
		          		           		    SearchSql=" and build_id='"+build_id+"'";
		          		      		  //      alert("ceach:"+SearchSql); 
		          		      		        $.ajax({
		          		      		           url:"ht/unit/SelectBySql.do",
		          		      	    	        //async:false,
		          		      	                datatype:'json', 
		          		      	                data:{'SearchSql':SearchSql}, // 发送数据   
		          		      	                error:function(data){  
		          		      	                alert("单元出错了！！");  
		          		      	            },  
		          		      	            success:function(data){
		          		      	       	  //  alert("namber:"+data.rows.length);
		          		      	            var select2 = document.getElementById("unit");
		          		      	       	    if(len>0){
		          		      	           	    for(var i=0;i<=len;i++){
		          		      	           		    select2.options.add(new Option(data.rows[i].unit_code, data.rows[i].unit_id)); 
		          		      	           	        if(select2.options[i].value==unit_id){
		          		      	           	        	select2.options[i].selected=true;
		          		      	           	     //房间
		          		      	           	     SearchSql=" and unit_id='"+unit_id+"'";
		          		      	     		         alert("ceach:"+SearchSql);
		          		      	     		         $.ajax({
		          		      	     	    	         url:"ht/room/selectBySql.do",
		          		      	     	                 datatype:'json', 
		          		      	     	                 data:{'SearchSql':SearchSql}, // 发送数据   
		          		      	     	                 error:function(data){  
		          		      	     	                 alert("房间出错了！！");  
		          		      	     	                 },  
		          		      	     	                 success:function(data){
		          		      	     	       	     var len=data.rows.length;
		          		      	     	 //      	     alert("namber:"+data.rows.length);
		          		      	     	             var select3 = document.getElementById("room");
		          		      	     	       	     if(len>0){
		          		      	     	           	      for(var i=0;i<=len;i++){
		          		      	     	           		      select3.options.add(new Option(data.rows[i].room_code, data.rows[i].room_id)); 
		          		      	     	           	          if(select3.options[i].value==room_id){
		          		      	     	           	        	  select3.options[i].selected=true;
		          		      	     	           	          }
		          		      	     	           	      }
		          		      	     	       	     }
		          		      	     	       		
		          		      	     	       	 }
		          		      	     	 
		          		      	     	       });
		          		      	           	        }
		          		      	           	    }
		          		      	          	}
		          		      	       	    }

		          		      	            });
		          		           		}
		          		           		
		          		           	}
		          		       	}
		          		       	
		          		       }
		          	       });
		           		}
    	           	}
    	           
    	       	}

    	       }
    		 });
       }     
       });
        	 
        	 
        		
});
</script>
<script type="text/javascript">
<!--项目-->
function selectProject(){
	var SearchSql;
		$.ajax({
	    	url:"./ht/project/selectAll1.do",
	        datatype:'json', 
	        //data:{'SearchSql':SearchSql}, // 发送数据   
	        error:function(data){  
	            alert("出错了！！");  
	       },  
	       success:function(data){
             //alert("12132");
	       	var len=data.rows.length;
	       	//alert(len);
	        var select = document.getElementById("project");
	        //alert(select.value);
	       	if(len>0){
	       	
	           	for(var i=0;i<=len;i++){
	           		select.options.add(new Option(data.rows[i].project_name, data.rows[i].project_id)); 
	           	}

	       	}else{
	       		alert("项目不存在！！！");
	       	}
	       	
	       }
	 
	        });
	}
<!--楼栋 -->	
function selectBuild(){
	var SearchSql;
	var project= $("#project").val();
	
	if(project!=""){
		SearchSql=" and project_id='"+project+"'";

		$.ajax({
	    	url:"ht/build/selectBySql.do",
	        datatype:'json', 
	        data:{'SearchSql':SearchSql}, // 发送数据   
	        error:function(data){  
	            alert("出错了！！");  
	       },  
	       success:function(data){

	       	var len=data.rows.length;
	        var select = document.getElementById("build");
	       	if(len>0){
	       		
	           	for(var i=0;i<=len;i++){
	           		select.options.add(new Option(data.rows[i].build_name, data.rows[i].build_id)); 
	           	}

	       	}else{
	       		alert("不存在这个楼栋！！！");
	       	}
	       	
	       }
	 
	        });
	   }
	}
	
<!--单元 -->	
function selectUnit(){
	var SearchSql;
	var build= $("#build").val();

	if(build!=""){
		SearchSql=" and build_id='"+build+"'";
         alert(SearchSql);
		$.ajax({
	    	url:"ht/unit/SelectBySql.do",
	        datatype:'json', 
	        data:{'SearchSql':SearchSql}, // 发送数据   
	        error:function(data){  
	            alert("出错了！！");  
	       },  
	       success:function(data){
	     
	       	var len=data.rows.length;

	        var select = document.getElementById("unit");
	       	if(len>0){
	       		
	           	for(var i=0;i<=len;i++){
	           		select.options.add(new Option(data.rows[i].unit_code, data.rows[i].unit_id)); 
	           	}
	          
	       	}else{
	       		alert("不存在这个单元！！！");
	       	}
	       	
	       }
	 
	        });
	   }
	}
<!--房间 -->	
function selectRoom(){
	var SearchSql;
	var unit= $("#unit").val();
	if(build!=""){
		SearchSql=" and unit_id='"+unit+"'";
	
		
		
		alert("ceach:"+SearchSql);
		$.ajax({
	    	url:"ht/room/selectBySql.do",
	        datatype:'json', 
	        data:{'SearchSql':SearchSql}, // 发送数据   
	        error:function(data){  
	            alert("出错了！！");  
	       },  
	       success:function(data){
	     
	       	var len=data.rows.length;
	        var select = document.getElementById("room");
	       	if(len>0){
	       		
	           	for(var i=0;i<=len;i++){
	           		select.options.add(new Option(data.rows[i].room_code, data.rows[i].room_id)); 
	           	}
	           
	       	}else{
	       		alert("不存在这个房间！！！");
	       		
	       	}
	       	
	       }
	 
	        });
	   }
	}
</script>
<script type="text/javascript">

//修改
    function ajaxUpdate(){
    	var receive={
    			sale_chance_id:$("#id").val(),
    			intention_description:$("#intention_description").val(),
        		customer_id:$("#customer_id").val(),
        		customer_name:$("#customer_name").val(),
        		tel:$("#tel").val(),
        		user_id:$("#user_id").val(),
        		user_name:$("#userName").val(),
        		project_id:$("#project").val(),
        		build_id:$("#build").val(),
        		unit_id:$("#unit").val(),
        		room_id:$("#room").val(),
        		number:$("#number").val(),
        		sale_chance_name:$("#sale_chance_name").val()
        	
        	};
    	
    	//alert("receive："+receive);
        $.ajax({ 	
        data: receive,
        type:"Post",  
        dataType: 'json',  
        url:"Sale_Chance/updateSale_Chance.do", 
        error:function(data){  
             alert("出错了！！");  
        },  
        success:function(data){
        	alert('销售机会修改成功！');
        	window.location.href = 'listSale_Chance.jsp'; 
         }  
         });  
     } 
    // 重置
    function ajaxReset(){

    	$("#sale_chance_name").val("");
		$("#room").val("");
		$("#unit").val("");
		$("#build").val("");
        $("#customer_name").val("");
        $("#tel").val("");
    	$("#number").val("");
    	$("#userName").val("");
    	$("intention_description").val("");
		
    }
</script>
<!-- 验证 -->
<script type="text/javascript">
   function checkintention_description(){
	  var intention_description= $("#intention_description").val();
	  if(intention_description==""){
		 alert("意向描述不能为空！"); 
		 $("#intention_description").focus();
		 return false;
	  }
	  return true;
   }
   
   function checkNumber(){
		  var number= $("#number").val();
		  if(number==""){
			 alert("业务员编号不能为空！"); 
			 $("#number").focus();
			 return false;
		  }
		  return true;
	   }
     
   function checkcustomer_name(){
		  var customer_name= $("#customer_name").val();
		  if(customer_name==""){
			 alert("客户姓名不能为空！"); 
			 $("#customer_name").focus();
			 return false;
		  }
		  return true;
	   }
   
   function checkRoom(){
		  var room= $("#room").val();
		  if(room==""){
			 alert("意向房间不能为空！"); 
			 $("#room").focus();
			 return false;
		  }
		  return true;
	   }
   function checksale_chance_name(){
		  var sale_chance_name= $("#sale_chance_name").val();
		  if(sale_chance_name==""){
			 alert("机会名称不能为空！"); 
			 $("#sale_chance_name").focus();
			 return false;
		  }
		  return true;
	   }
   
   function checkAll(){
		  return checkintention_description()&&checkNumber()&&checkcustomer_name()&&checkRoom()&&checksale_chance_name();
	   }
</script>
<!-- 查询 -->
<script type="text/javascript">
function select(){
var SearchSql;
var number= $("#number").val();
alert(number);
if(number!=""){
	SearchSql=" and number='"+number+"'";
}
	
	//alert("123");
	alert("ceach:"+SearchSql);
	$.ajax({
    	url:"ht/selectBySql.do",
        datatype:'json', 
        data:{'SearchSql':SearchSql}, // 发送数据   
        error:function(data){  
            alert("出错了！！");  
       },  
       success:function(data){
       	//alert('业务员信息查询成功！');
       	//window.location.href = 'listclient.jsp'; 
       	//alert(data);
       	//console.log("---------"+data);
       	var len=data.rows.length;
       	alert("namber:"+data.rows.length);
       	if(len>0){
       		//alert( data.rows[0].id);
           	//alert( data.rows[0].userName);
           	$("#user_id").val(data.rows[0].user_id),
           	$("#userName").val(data.rows[0].name)
       	}else{
       		alert("这个业务员不存在！！！");
       		$("#number").val("");
       		$("#userName").val("");
       		$("#number").focus();
       	}
       	
       }
 
        });
}

function selectcustomer_name(){
	var SearchSql;
	var customer_name= $("#customer_name").val();
	alert("customer_name:"+customer_name);
	if(customer_name!=""){
		SearchSql=" and customer_name='"+customer_name+"'";
	
		
		//alert("123");
		alert("ceach:"+SearchSql);
		$.ajax({
	    	url:"./Customer/selectBySql.do",
	        datatype:'json', 
	        data:{'SearchSql':SearchSql}, // 发送数据   
	        error:function(data){  
	            alert("123出错了！！");  
	       },  
	       success:function(data){
	       	var len=data.rows.length;
	       	//alert("namber:"+data.rows.length);
	        var select = document.getElementById("tel");
	        $("#customer_id").val(data.rows[0].customer_id)
	       	if(len>0){
	           	for(var i=0;i<=len;i++){
	           		select.options.add(new Option(data.rows[i].tel, data.rows[i].tel)); 
	           	}
	       	}else{
	       		alert("这个客户不存在！！！");
	       		$("#customer_name").val("");
	       		$("#customer_name").focus();
	       	}
	       	
	       }
	 
	        });
	}
}
</script>

</head>
<body>
<div class="yboxwidth boxcenter">
  <div class="ybox09">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
       <td style="padding-left: 20px"><table border="0" cellspacing="0" cellpadding="0">
          <tr valign="top" >
            <td class="ybox11td5" ></td>
            <td class="ybox11td6" >修改销售机会</td>
            <td class="ybox11td7"></td>
            <td class="ybox11td2"></td>
            <td class="ybox11td3"></td>
            <td class="ybox11td2"></td>
            <td class="ybox11td3"></td>
            <td class="ybox11td2"></td>
            <td class="ybox11td4"></td>    
          </tr>
        </table></td>
        </tr>
    </table>
  </div>
  <div class="ybox02">
  <form action="" class="f1" id="f1">
    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="margb4">
      <tr>
        <td class="ybox03td1"></td>
        <td class="ybox03td2"></td>
        <td class="ybox03td3"></td>
      </tr>
      <tr>
        <td class="ybox03td4"></td>
        <td class="ybox03td5"><div class="ybox05 margb8">
            <dl>
              <dt><strong>销售机会信息</strong> </dt>
            </dl>
            <input type="hidden" id="user_id"  />
            <input type="hidden" id="id"  />
            <input type="hidden" id="customer_id"  />
          </div>
          <table width="100%" border="0" cellpadding="0" cellspacing="1" class="ybox04table">
            <tr>
               <td width="9%" class="ybox04tdl"><span class="red">*</span>机会名称</td>
               <td width="15%" class="ybox04tdr" colspan="8">
                  <input type="text"  name="sale_chance_name" id="sale_chance_name" class="black12" style="width:90%;"/>
               </td>
               
            </tr>
            <tr>
              <td width="9%" class="ybox04tdl"><span class="red">*</span>意向项目</td>
              <td width="15%" class="ybox04tdr">
                  <select id="project" name="project" style="width: 150px" onclick="selectProject()" onchange="selectBuild()"> 
                  </select>
              </td>
              <td width="9%" class="ybox04tdl"><span class="red">*</span>意向楼栋</td>
              <td width="15%" class="ybox04tdr">
                  <select id="build" style="width: 150px" onchange="selectUnit()">
                  </select>
              </td>
              <td width="9%" class="ybox04tdl"><span class="red">*</span>意向单元</td>
              <td width="15%" class="ybox04tdr">
                  <select id="unit" style="width: 150px" onchange="selectRoom()">
                  </select>
              </td>
              <td width="9%" class="ybox04tdl"><span class="red">*</span>意向房间</td>
              <td width="15%" class="ybox04tdr">
                  <select id="room" style="width: 150px"> 
                  </select>
              </td>
            </tr>
          </table></td>
        <td class="ybox03td6"></td>
      </tr>
      <tr>
        <td class="ybox03td4"></td>
        <td class="ybox03td5">
          <table width="100%" border="0" cellpadding="0" cellspacing="1" class="ybox04table">
             <tr>
             <td width="9%" class="ybox04tdl"><span class="red">*</span>客户姓名</td>
              <td width="15%" class="ybox04tdr">
                  <input id="customer_name" name="customer_name"type="text"  class="black12" style="width:90%;" />
                  <!-- onblur="selectcustomer_name()" -->
              </td>
              <td width="9%" class="ybox04tdl">客户联系方式</td>
              <td width="15%" class="ybox04tdr">
              <input id="tel" name="tel"type="text"  class="black12" style="width:90%;"/>
                  
              </td>
            
              <td width="9%" class="ybox04tdl"><span class="red">*</span>业务员编号</td>
              <td width="15%" class="ybox04tdr">
              <input name="number" type="text"  class="black12" id="number" style="width:80%;"/>
              <img src="images/select.gif"  style="cursor: pointer;" onclick="select()" />
               </td>
              <td width="9%" class="ybox04tdl"> 业务员姓名</td>
              <td width="15%" class="ybox04tdr"><input name="userName" type="text"  class="black12" id="userName" style="width:90%;" disabled="disabled" /></td>
              </tr>
              <tr>
                  <td width="9%" class="ybox04tdl" style="padding-bottom: 65px"><span class="red">*</span> 意向描述</td>
                  <td width="15%" class="ybox04tdr" colspan="7">
                     <textarea rows="5" cols="150" name="intention_description" id="intention_description"></textarea>
                  </td>
                  
              </tr>
              <tr><td class="ybox04tdr" colspan="8">
               <dl><!-- 标注 -->
                 <dt><strong></strong> 
                 
                 
              </dt>
               </dl>
            </td>
            </tr>
            
          </table></td>
        <td class="ybox03td6"></td>
      </tr>
      <tr>
        <td class="ybox03td7"></td>
        <td class="ybox03td8"></td>
        <td class="ybox03td9"></td>
      </tr>
    </table>
    <table width="380" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td height="60" align="center"><img src="images/bottoncommit.gif"  style="cursor: pointer;"width="95" height="34" onclick="return checkAll()&&ajaxUpdate()" /></td>
        <td height="60" align="center"><img src="images/bottonreset.gif" style="cursor: pointer;" width="95" height="34" onclick="ajaxReset()" /></td>
      </tr>
    </table>
      </form>
  </div>

</div>
</body>
</html>

